set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible            " 关闭 vi 兼容模式
""syntax on                   " 自动语法高亮
syntax enable
set number                  " 显示行号
set cursorline              " 突出显示当前行
set ruler                   " 打开状态栏标尺
set shiftwidth=2            " 设定 << 和 >> 命令移动时的宽度为 2
set softtabstop=2           " 使得按退格键时可以一次删掉 2 个空格
set tabstop=2               " 设定 tab 长度为 2
set shortmess=atI           " 去掉欢迎界面
set autochdir               " 自动切换当前目录为当前文件所在的目录
filetype plugin indent on   " 开启插件
set backupcopy=yes          " 设置备份时的行为为覆盖
""set ignorecase smartcase    " 搜索时忽略大小写，但在有一个或以上大写字母时仍保持对大小写敏感
set nowrapscan              " 禁止在搜索到文件两端时重新搜索
set incsearch               " 输入搜索内容时就显示搜索结果
set hlsearch                " 搜索时高亮显示被找到的文本
set noerrorbells            " 关闭错误信息响铃
set novisualbell            " 关闭使用可视响铃代替呼叫
""set t_vb=                   " 置空错误铃声的终端代码
""set showmatch               " 插入括号时，短暂地跳转到匹配的对应括号
""set matchtime=2             " 短暂跳转到匹配括号的时间
set magic                   " 设置魔术
set hidden                  " 允许在有未保存的修改时切换缓冲区，此时的修改由 vim 负责保存
set guioptions-=T           " 隐藏工具栏
set guioptions-=m           " 隐藏菜单栏
set smartindent             " 开启新行时使用智能自动缩进
set backspace=indent,eol,start
                            " 不设定在插入状态无法用退格键和 Delete 键删除回车符
set cmdheight=1             " 设定命令行的行数为 1
set laststatus=2            " 显示状态栏 (默认值为 1, 无法显示状态栏)
set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
                            " 设置在状态行显示的信息
""set noswf   " 去掉烦人的交换文件
set backup
set backupdir=$VIM/bakfile
set directory=$VIM/swapfile
set undodir=~/.undodir

"set guifont=Courier:h15 " 字体 && 字号
set guifont=Consolas:h16 " 字体 && 字号
set helplang=cn,en

"设置缩进
set tabstop=2                " 设置tab键的宽度
set shiftwidth=2             " 换行时,行间交错使用2个空格
""set autoindent             " 自动对齐
set backspace=2              " 设置退格键可用
set cindent shiftwidth=2     " 自动缩进2空格
set smartindent              " 智能自动缩进
set ai                      " 设置自动缩进
set nu                    " 显示行号
set showmatch               " 显示括号配对情况
 if &term=="xterm"
     set t_Co=8
     set t_Sb=^[[4%dm
     set t_Sf=^[[3%dm
 endif
""set nowrap                                 "不换行
set linebreak                             " 整词换行
"===================="设置背景主题===={{"
colorscheme desert
"===================="设置背景主题====}}"
" ======= 引号 && 括号自动匹配 ======= "
 :inoremap ( ()<ESC>i
 :inoremap ) <c-r>=ClosePair(')')<CR>
 :inoremap { {}<ESC>i
 :inoremap } <c-r>=ClosePair('}')<CR>
 :inoremap [ []<ESC>i
 :inoremap ] <c-r>=ClosePair(']')<CR>
 :inoremap < <><ESC>i
 :inoremap > <c-r>=ClosePair('>')<CR>
 :inoremap " ""<ESC>i
 :inoremap ' ''<ESC>i
 :inoremap ? ??<ESC>i
 function ClosePair(char)
     if getline('.')[col('.')-1] == a:char
         return "\<Right>"
     else
         return a:char
     endif
 endf
"设置VIM记录的历史数
 set history=1000
"设置增量搜索模式
 set incsearch
"设置静音模式
set noerrorbells
set novisualbell
""""""""""""""""""""""""""""
" 删除所有行未尾空格
nmap <F5> :%s/[ \t\r]\+$//g<CR>
" 删除所有空行
nmap <F6> :g/^$/d<CR>
"合并所有的行，为一行
nmap <F7> :%j<CR>
"合并连续的空格为一个空格
nmap <F8> :%s/\s\+/ /g<CR>
"一些不错的映射转换语法（如果在一个文件中混合了不同语言时有用）
nmap <leader>1 :set filetype=xhtml<CR>
nmap <leader>2 :set filetype=css<CR>
nmap <leader>3 :set filetype=javascript<CR>
nmap <leader>4 :set filetype=php<CR>
" 显示Tab符
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
set list
" 在行和段开始处使用制表符
  set smarttab
" 自动格式化
"set formatoptions=tcrqn
set foldenable              " 开始折叠
set foldmethod=syntax       " 设置语法折叠
set foldmethod=indent "set default foldmethod
set foldcolumn=0            " 设置折叠区域的宽度
setlocal foldlevel=20       " 设置折叠层数为
""set foldclose=all           " 设置为自动关闭折叠
map <F10> :set foldlevel=20 <CR>
" 用空格键来开关折叠
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc':'zo')<CR>
"当文件在外部被修改，自动更新该文件
set autoread
" 字符间插入的像素行数目
set linespace=0
""上一文件
map <F3> :bp <CR>
""下一文件
map <F4> :bn <CR>
nnoremap j gj
nnoremap k gk
xnoremap j gj
xnoremap k gk
set fencs=utf-8
set encoding=utf-8
set fileencodings=utf-8,gb2312,cp936,latin-1     " 打开文件时会根据fileencodings选项来识别文件编码
set fileencoding=utf-8                    " 保存新建文件时会根据fileencoding的设置编码来保存
language messages zh_CN.utf-8  " 解决consle输出乱码
set termencoding=utf-8
" 读文件时自动设定当前目录为刚读入文件所在的目录
autocmd BufReadPost * cd %:p:h
" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l
map <F11> :source $VIM/vimfiles/plugin/clean.vim
"运行可执行文件
map <F12> :call RunResult()<CR>
func! RunResult()
exec "w"
if &filetype == "c"
exec "! %<"
elseif &filetype == "cpp"
exec "! %<"
elseif &filetype == "go"
exec "! %<"
elseif &filetype == "haskell"
exec "! %<"
elseif &filetype == "java"
exec "!javac %<.java"
exec "!java %<"
elseif &filetype == "cs"
exec "! %<"
elseif &filetype == "asm"
exec "! %<"
elseif &filetype == "sh"
exec "!sh %<.sh"
elseif &filetype == "lua"
exec "!lua %<.lua"
elseif &filetype == "perl"
exec "!perl %<.pl"
elseif &filetype == "python"
exec "!python %<.py"
elseif &filetype == "ruby"
exec "!ruby %<.rb"
elseif &filetype == "vim"
exec "source %"
endif
endfunc
" 插入模式下上下左右移动光标
inoremap <c-h> <left>
inoremap <c-l> <right>
inoremap <c-j> <c-o>gj
inoremap <c-k> <c-o>gk
set formatoptions=tcrqn    " 自动格式化
set incsearch  " 在搜索时，输入的词句的逐字符高亮（类似firefox的搜索）
map <F2> :call SplitbyLess()<CR>
func! SplitbyLess()
  exec "split css/style_cg.less"
endfunc
let mapleader = ","
map <C-U> <C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y>
map <C-D> <C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E>
set display=lastline
""nerd_tree 配置
let NERDTreeWinPos='right'
nmap <leader>n :NERDTreeToggle<cr>
""窗口启动最大化
if has("win32")
au GUIEnter * simalt ~x
else
function Maximize_Window()
  silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
endfunction
au GUIEnter * call Maximize_Window()
endif
" c-j自动补全，当补全菜单打开时，c-j,k上下选择
imap <expr> <c-j>      pumvisible()?"\<C-N>":"\<C-X><C-O>"
imap <expr> <c-k>      pumvisible()?"\<C-P>":"\<esc>"
" {{{ 编码字体设置
"   if has("multi_byte")
"     set encoding=unicode
"     let &termencoding = &encoding
"     " Set default encoding as UTF-8 with not BOM
"     setglobal fileencoding=utf-8 bomb
"     " Auto detect the file encoding BOM unicode, utf-8, GBK, Big5, Latin1
"     set fileencodings=ucs-bom,utf-8,cp936,cp950,latin1
"
"     " Walkaround the encoding problem for fenc=utf-8 && enc=ucs-2
"     augroup i18n
"         autocmd!
"         autocmd BufReadPost * if &fileencoding == "utf-8" | let &encoding = &fileencoding | endif
"     augroup END
"   endif
""set termencoding=chinese
""set fileencodings=ucs-bom,utf-8,cp936,cp950,latin1
""set ambiwidth=double
""set guifont=YaHei\ Consolas\ Hybrid:h12
" }}}
map <F9> :promptr <CR>
"zencoding 配置起始"
let g:user_zen_settings = {
  \  'indentation' : '	',
  \  'perl' : {
  \    'aliases' : {
  \      'req' : 'require '
  \    },
  \    'snippets' : {
  \      'use' : "use strict\nuse warnings\n\n",
  \      'warn' : "warn \"|\";",
  \    }
  \  }
  \}
  let g:user_zen_expandabbr_key = '<c-l>'
  let g:use_zen_complete_tag = 1
"zencoding 配置结束"
" 不要闪烁
set novisualbell
set completeopt=longest,menu
"vim自带补全
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType java set omnifunc=javacomplete#Complete
"字典补全配置起始
"{不管用的
""let s:extfname = expand("%:e")
""if s:extfname ==?"css"
	""set complete +=k
""endif
"}
""au FileType less call AddLessFuncList()
""function AddLessFuncList()
    ""set dictionary-=D:/dict/css.dict dictionary+=D:/dict/css.dict
""    set complete-=k complete+=k
""endfunction
set iskeyword+=-
""字典补全配置结束
"=======超级补全配置
""source $VIM/vimfiles/neocomplcache.vim
"{{{taglist配置
let Tlist_Show_One_File = 1            "不同时显示多个文件的tag，只显示当前文件的
let Tlist_Exit_OnlyWindow = 1          "如果taglist窗口是最后一个窗口，则退出vim
let Tlist_Use_Right_Window = 1    "在右侧窗口中显示taglist窗口
map <silent> <leader>tl :TlistToogle<cr>
"}}}
"{{{
" autoload _vimrc
""autocmd! bufwritepost _vimrc source %
"}}}"
map <CapsLock> <Esc>
"{{{ vundle 配置
filetype off
" 此处规定Vundle的路径
set rtp+=$VIM/vimfiles/bundle/vundle/
call vundle#rc('$VIM/vimfiles/bundle/')
Bundle 'gmarik/vundle'
filetype plugin indent on
" original repos on github<br>Bundle 'mattn/zencoding-vim'
Bundle 'drmingdrmer/xptemplate'
" vim-scripts repos
""Bundle 'FuzzyFinder'
""Bundle 'taglist.vim'
""Bundle 'closetag.vim'
""Bundle 'AutoComplPop'
""Bundle 'rubycomplete.vim'
Bundle 'matchit.zip'
Bundle 'vitalk/vim-lesscss'
Bundle 'genoma/vim-less'
Bundle 'mattn/zencoding-vim'
Bundle 'tomtom/likelycomplete_vim'
Bundle 'jcorbin/vim-searchmatch'
Bundle 'tpope/vim-surround'
Bundle 'tomtom/checksyntax_vim'
Bundle 'Shougo/neocomplcache.vim'
Bundle 'jsbeautify'
Bundle 'closetag.vim'
Bundle 'EasyHtml.vim'
filetype plugin indent on     " required!
"}}}vundle 配置

